<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>全选/反选</title>
    <script src="js/jquery-1.12.4.js"></script>
</head>
<body>
<table border="1" align="center" width="60%" height="500px" cellspacing="0" cellpadding="5px">
    <tr>
        <th>
            <input type="button" value="全选" id="qx">
            <input type="button" value="反选" id="fx">
        </th>
        <th>序号</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>地址</th>
        <th>电话</th>
    </tr>
    <tr>
        <td><input type="checkbox"></td>
        <td>1</td>
        <td>王佳欣</td>
        <td>18</td>
        <td>中国北科</td>
        <td>15812341234</td>
    </tr>
    <tr>
        <td><input type="checkbox" checked="checked"></td>
        <td>2</td>
        <td>王佳欣</td>
        <td>18</td>
        <td>中国北科</td>
        <td>15812341234</td>
    </tr>
    <tr>
        <td><input type="checkbox"></td>
        <td>3</td>
        <td>王佳欣</td>
        <td>18</td>
        <td>中国北科</td>
        <td>15812341234</td>
    </tr>
    <tr>
        <td><input type="checkbox"></td>
        <td>4</td>
        <td>王佳欣</td>
        <td>18</td>
        <td>中国北科</td>
        <td>15812341234</td>
    </tr>
    <tr>
        <td><input type="checkbox"></td>
        <td>5</td>
        <td>王佳欣</td>
        <td>18</td>
        <td>中国北科</td>
        <td>15812341234</td>
    </tr>
    <tr>
        <td><input type="checkbox"></td>
        <td>6</td>
        <td>王佳欣</td>
        <td>18</td>
        <td>中国北科</td>
        <td>15812341234</td>
    </tr>
    <tr>
        <td><input type="checkbox"></td>
        <td>7</td>
        <td>王佳欣</td>
        <td>18</td>
        <td>中国北科</td>
        <td>15812341234</td>
    </tr>
    <tr>
        <td><input type="checkbox"></td>
        <td>8</td>
        <td>王佳欣</td>
        <td>18</td>
        <td>中国北科</td>
        <td>15812341234</td>
    </tr>
    <tr>
        <td><input type="checkbox"></td>
        <td>9</td>
        <td>王佳欣</td>
        <td>18</td>
        <td>中国北科</td>
        <td>15812341234</td>
    </tr>
</table>
</body>
<script>
$(function() {
    //获取所有的多选按钮
    // $("input[type=checkbox]")
    $("#qx").click(function(){
        $("input[type=checkbox]").attr("checked", true);
    });
    $("#fx").click(function(){
        // $("input[type=checkbox]").attr("checked", true);
        var checkboxs = $("input[type=checkbox]");
        for (var i = 0; i <checkboxs.length; i++) {
        //     // if(checkboxs[i].checked){
        //     //     checkboxs[i].checked = false;
        //     // }else{
        //     //     checkboxs[i].checked = true;
        //     // }
            checkboxs[i].checked = !checkboxs[i].checked;
        }
    });
});

</script>
</html>